package top.market.controller;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.market.model.dto.MarketSettingDTO;
import top.market.model.dto.QueryCategoryDTO;
import top.market.model.entity.Category;
import top.market.model.vo.MarketInfoVO;
import top.market.model.vo.Result;
import top.market.redis.LyhStringRedisTemplate;
import top.market.service.RedisService;

import java.math.BigDecimal;

/**
 * @Description:
 * @Author: liyuhai
 * @Date: 2025/3/27
 */
@RestController
@RequestMapping("/market")
public class MarketSettingController {

    @Autowired
    LyhStringRedisTemplate redisTemplate;

    @GetMapping("/status")
    public Result getMrarketStatus() {
        Integer status = redisTemplate.getObjStr("status", Integer.class);
        return Result.ok("", status);
    }
    @PutMapping("/status/update")
    public Result getMrarketStatus(@RequestBody MarketSettingDTO settingDTO) {
        if (settingDTO.getStatus() != null){
            redisTemplate.setObjStr("status", settingDTO.getStatus());
        }
        return Result.ok("配置修改成果");
    }
    @GetMapping("/getMarketInfo")
    public Result getMarketInfo() {
        MarketInfoVO marketInfo = redisTemplate.getObjStr("marketInfo", MarketInfoVO.class);
        if (marketInfo == null) {
            marketInfo = new MarketInfoVO();
            marketInfo.setPhone("17612121212");
            marketInfo.setShopAddress("北京朝阳区");
            marketInfo.setDeliveryFee(new BigDecimal("2.50"));
        }
        return Result.ok("", marketInfo);
    }

    @PutMapping("/setMarketInfo")
    public Result setMarketInfo(@RequestBody MarketInfoVO marketInfoVO) {
        if (marketInfoVO == null || marketInfoVO.getPhone() == null || marketInfoVO.getShopAddress() == null) {
            return Result.error("没有数据");
        }
        redisTemplate.setObjStr("marketInfo", marketInfoVO);
        return Result.ok("成功", marketInfoVO);
    }
}
